<?php

global $db_table_version, $wpdb;
$db_table_version = "1.0";

function db_install() {

    global $db_table_version, $wpdb;
    $installed_ver = get_option( "db_table_version" );
    $table_name = $wpdb->prefix .'compay';
    if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name ||  $installed_ver != $db_table_version ) {

    $sql = "CREATE TABLE $table_name (
            teamid mediumint(9) NOT NULL AUTO_INCREMENT,
            teamname tinytext NOT NULL,
            pname1 tinytext NOT NULL,
            pid1 smallint NOT NULL,
            pname2 tinytext NOT NULL,
            pid2 smallint NOT NULL,
            pname3 tinytext NOT NULL,
            pid3 smallint NOT NULL,
            pname4 tinytext NOT NULL,
            pid4 smallint NOT NULL,
            UNIQUE KEY id (id)
            );";
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
    update_option( "db_table_version", $db_table_version );
    }
}

function db_uninstall(){
    global $db_table_version, $wpdb;;
    $table_name = $wpdb->prefix .'compay';
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta('DROP '.$table_name);
}
?>